<template>
	<view :style="[{paddingTop:CustomBar+'px'}]">
		<cu-custom bgColor="bg-white" :isBack="true" fatherCss="box-shadow:none">
			<block slot="backText"></block>
			<block slot="content">兑换卡券</block>
		</cu-custom>
		<view class="particulars-cont">
			<view class="detail-list">
				<view class="item" v-for="(item,index) in voucherList" :key="index">
					<view class="orange">
						<image :src="item.goods_image" mode=""></image>
					</view>
					<view class="info">
						<view class="">
							<view class="">
								{{item.product_name}}
							</view>
							<view class="">截止时间:{{item.end_time}}</view>
						</view>
						<view class="price">
							<view class="" @click="goCoinNew" v-if="item.status==0" :data-id="item.id">
								去兑换
							</view>
							<view class="" @click="saveOrder" v-if="item.status==1 || item.status==2" :data-id="item.order_id">
								确认收货
							</view>
							<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/past-due.png" mode="" v-if="item.status==5"></image>
							<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/%E5%85%8D%E5%8D%95%E9%80%9AApp/drop-shipping.png"
							 mode="" v-if="item.status==1"></image>
							<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/%E5%85%8D%E5%8D%95%E9%80%9AApp/has-received.png"
							 mode="" v-if="item.status==3"></image>
							<image src="https://xarkbucket.oss-cn-hangzhou.aliyuncs.com/%E5%85%8D%E5%8D%95%E9%80%9AApp/shipped.png" mode=""
							 v-if="item.status==2"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<no-content :showType="'card2'" v-if='noContent' :tips="'你暂时没有可兑换的商品~'"></no-content>
		<tui-divider width="60%" :gradual="true" v-if="noMore">没有更多了~</tui-divider>
	</view>
</template>

<script>
	import noContent from './component/noContent'
	import tuiDivider from './component/divider'
	export default {
		components: {
			noContent,
			tuiDivider
		},
		data() {
			return {
				typeText: '',
				CustomBar: this.CustomBar,
				scrollH: '',
				page: 1,
				lastPage: '',
				noContent: false,
				noMore: false,
				voucherList: []
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: '#ffffff'
			})
		},
		onLoad(options) {
			if (options.status) {
				this.typeText = options.status == 1 ? '账单明细' : '积分明细'
			}
			uni.getSystemInfo({
				success: (res) => {
					this.scrollH = res.windowHeight
				}
			})
			this.getListAll()
		},
		onShow() {
			if (uni.getStorageSync('changeGoodId')) {
				var list = this.voucherList
				list.forEach(item => {
					if (item.id == uni.getStorageSync('changeGoodId')) {
						item.status = 1
					}
				})
				uni.removeStorageSync('changeGoodId')
				this.voucherList = list
			}
		},
		methods: {
			goCoinNew(e) {
				// #ifdef MP-WEIXIN
				uni.showModal({
					title: '温馨提示',
					content: '请前往【掌商APP】领取礼物'
				})
				return
				// #endif
				// #ifdef H5
				uni.showModal({
					title: '温馨提示',
					content: '请前往【掌商APP】领取礼物'
				})
				return
				// #endif
				uni.navigateTo({
					url: '/pages/forGoods?orderId=' + e.currentTarget.dataset.id
				})
			},
			saveOrder(e){
				var that = this
				var id = e.currentTarget.dataset.id
				this.$request({
					url: '/HelpOrder/confirm_delivery',
					data: {
						order_id: id
					},
					success: res => {
						if (res.data.status == 1) {
							uni.showModal({
								content:"确认收货成功，期待再次为您服务！",
								showCancel:false,
								success() {
									that.page = 1
									that.noContent = false
									that.noMore = false
									that.getListAll()
								}
							})
						}
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getListAll() {
				var that = this
				this.$request({
					url: '/HelpOrder/get_order_list',
					data: {
						page: that.page
					},
					success: res => {
						if (res.data.status == 1) {
							if (res.data.data.totalNum == 0) {
								that.noContent = true
								return
							}
							that.voucherList = that.voucherList.concat(res.data.data.data)
							that.page++
							that.lastPage = res.data.data.pageCount
							if (res.data.data.pageCount == 1 && that.page == 2) {
								that.noMore = true
							}
						}
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
			},
		},
		onReachBottom() {
			if (this.page > this.lastPage) {
				this.noMore = true
				return
			}
			this.getListAll()
		}
	}
</script>

<style>
	page {
		background: #f5f5f5;
	}
</style>
<style scoped>
	.particulars-cont {
		width: 100%;
		background: #f5f5f5;
		margin: 0 auto;
	}


	.top-truth .active {
		border-bottom: 4rpx solid #f34930;
		color: #f34930;
	}

	.detail-list {
		width: 100%;
		padding: 30rpx 24rpx 0;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
	}

	.detail-list .item {
		display: flex;
		border-radius: 8rpx;
		margin-bottom: 30rpx;
	}

	.detail-list .item:last-child {
		margin-bottom: 0 !important;
	}

	.detail-list .item .orange {
		width: 160rpx;
		height: 160rpx;
		border-radius: 8rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;

		box-sizing: border-box;
	}

	.detail-list .item .orange image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 8rpx;
	}

	.detail-list .item .orange.active {
		background: #adadad !important;
	}


	.detail-list .item .orange view {
		color: #fff;
		font-size: 30rpx;
	}

	.detail-list .item .orange view text {
		font-size: 40rpx;
		font-weight: bold;
	}

	.detail-list .item .info {
		flex: 1;
		display: flex;
		justify-content: space-between;
		border-radius: 8rpx;
		background: #fff;
	}

	.detail-list .item .info>view:nth-child(1) {
		flex: 1;
		display: flex;
		flex-direction: column;
		padding: 20rpx;
		justify-content: space-between;
	}

	.detail-list .item .info>view:nth-child(1)>view:nth-child(1) {
		font-size: 28rpx;
		letter-spacing: 1rpx;
		color: #333333;
	}

	.detail-list .item .info>view:nth-child(1)>view:nth-child(2) {
		font-size: 20rpx;
		letter-spacing: 1rpx;
		color: #999999;
	}

	.detail-list .item .info>view:nth-child(2) {
		width: 160rpx;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative
	}

	.detail-list .item .info>view:nth-child(2) view {
		font-size: 28rpx;
		line-height: 48rpx;
		letter-spacing: 1rpx;
		color: #f34930;
		width: 140rpx;
		height: 48rpx;
		background-color: #ffffff;
		border-radius: 24rpx;
		border: solid 1rpx #f34930;
		text-align: center;
	}

	.detail-list .item .info>view:nth-child(2) image {
		width: 88rpx;
		height: 88rpx;
		position: absolute;
		right: 200rpx;
		top: 50%;
		transform: translateY(-50rpx);
		z-index: 99;
	}
</style>
